// pages/list/index.js
var my = require("../../utils/MyUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isActive: null,
    listMain: [],
    listTitles: [],
    fixedTitle: null,
    toView: 'inToView0',
    oHeight: [],
    scroolHeight: 0,
    scrollTop: 0
  },
  /**
   * 搜索
   * @param {*} e 
   */
  seach(e) {
    var t = this
    var _TOKEN = wx.getStorageSync('_TOKEN')
    if (e.detail.value != '') {
      my.request("/oa-applet/contacts-search", "get", {
        user_name: e.detail.value
      }, {
        token: _TOKEN
      }, function (res) {
        wx.hideLoading()
        if (res.data.code == 0) {
          if (res.data.data.length > 0) {
            t.setData({
              listMain: res.data.data
            })
          }
        }
      })
    }else{
      my.request("/oa-applet/contacts-list", "get", {}, {
        token: _TOKEN
      }, function (res) {
        if (res.data.code == 0) {
          wx.hideLoading()
          t.setData({
            listMain: res.data.data
          })
        }
      })
    }
  },

  ck(e) {
    var _TOKEN = wx.getStorageSync('_TOKEN')
    var t = this
    wx.navigateTo({
      url: 'info/index?uid='+e.currentTarget.dataset.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _TOKEN = wx.getStorageSync('_TOKEN')
    if (_TOKEN == "") {
      my.alerts("您还未登录，请登录之后再操作", function () {
        wx.switchTab({
          url: '../my/my',
        })
      })
    } else {
      var t = this
      my.request("/oa-applet/contacts-list", "get", {}, {
        token: _TOKEN
      }, function (res) {
        wx.hideLoading()
        if (res.data.code == 0) {
          t.setData({
            listMain: res.data.data
          })
        }
      })
    }
  },
  onHide: function () {

  },
})